#include "SemanticNodeBlockIf.h"

/**
 *  @fn	SemanticNodeBlockIf::SemanticNodeBlockIf(const SyntaxTreeNode *ifNodeParent,
 *  	SemanticNode *parent)
 * 
 *  @brief	Constructor. 
 * 
 *  @author	Nikola Novak
 *  @date	6/26/2009
 * 
 *  @param	ifNodeParent	If non-null, if node parent.
 *  @param	parent			If non-null, the parent.
 */
SemanticNodeBlockIf::SemanticNodeBlockIf(const SyntaxTreeNode *ifNodeParent, SemanticNode *parent) : SemanticNode(parent), LabeledNode(ifNodeParent->Nodes->GetData(0)) {
	const SyntaxTreeNode *theNode = ifNodeParent->Nodes->GetData(1)->Nodes->GetData(0);
	elseStructure = (theNode->Nodes->GetData(7)->Nodes->GetCount() > 0);
}
/**
 *  @fn	bool SemanticNodeBlockIf::hasElse(void)
 * 
 *  @brief	Query if this object has else. 
 * 
 *  @author	Nikola Novak
 *  @date	6/26/2009
 * 
 *  @return	true if else, false if not.
 */
bool SemanticNodeBlockIf::hasElse(void) {
	return elseStructure;
}
/**
 *  @fn	void SemanticNodeBlockIf::addBlockTerminate(SemanticNodeBlockTerminate *terminator,
 *  	bool which)
 * 
 *  @brief	Adds a block terminate to 'which'. 
 * 
 *  @author	Nikola Novak
 *  @date	6/26/2009
 * 
 *  @param	terminator	If non-null, the terminator.
 *  @param	which		true to which.
 */
void SemanticNodeBlockIf::addBlockTerminate(SemanticNodeBlockTerminate *terminator, bool which) {
	terminators.push_back(terminator);
	if (which) elseStructureNodeOrder.push_back(terminator);
	else thenStructureNodeOrder.push_back(terminator);
}
/**
 *  @fn	void SemanticNodeBlockIf::addBlockGenerate(SemanticNodeBlockGenerate *generator,
 *  	bool which)
 * 
 *  @brief	Adds a block generate to 'which'. 
 * 
 *  @author	Nikola Novak
 *  @date	6/26/2009
 * 
 *  @param	generator	If non-null, the generator.
 *  @param	which		true to which.
 */
void SemanticNodeBlockIf::addBlockGenerate(SemanticNodeBlockGenerate *generator, bool which) {
	generators.push_back(generator);
	if (which) elseStructureNodeOrder.push_back(generator);
	else thenStructureNodeOrder.push_back(generator);
}
/**
 *  @fn	void SemanticNodeBlockIf::addBlockAdvance(SemanticNodeBlockAdvance *advancer, bool which)
 * 
 *  @brief	Adds a block advance to 'which'. 
 * 
 *  @author	Nikola Novak
 *  @date	6/26/2009
 * 
 *  @param	advancer	If non-null, the advancer.
 *  @param	which		true to which.
 */
void SemanticNodeBlockIf::addBlockAdvance(SemanticNodeBlockAdvance *advancer, bool which) {
	advancers.push_back(advancer);
	if (which) elseStructureNodeOrder.push_back(advancer);
	else thenStructureNodeOrder.push_back(advancer);
}
/**
 *  @fn	void SemanticNodeBlockIf::addBlockEnter(SemanticNodeBlockEnter *entrant, bool which)
 * 
 *  @brief	Adds a block enter to 'which'. 
 * 
 *  @author	Nikola Novak
 *  @date	6/26/2009
 * 
 *  @param	entrant	If non-null, the entrant.
 *  @param	which	true to which.
 */
void SemanticNodeBlockIf::addBlockEnter(SemanticNodeBlockEnter *entrant, bool which) {
	entrants.push_back(entrant);
	if (which) elseStructureNodeOrder.push_back(entrant);
	else thenStructureNodeOrder.push_back(entrant);
}
/**
 *  @fn	void SemanticNodeBlockIf::addBlockLeave(SemanticNodeBlockLeave *leaver, bool which)
 * 
 *  @brief	Adds a block leave to 'which'. 
 * 
 *  @author	Nikola Novak
 *  @date	6/26/2009
 * 
 *  @param	leaver	If non-null, the leaver.
 *  @param	which	true to which.
 */
void SemanticNodeBlockIf::addBlockLeave(SemanticNodeBlockLeave *leaver, bool which) {
	leavers.push_back(leaver);
	if (which) elseStructureNodeOrder.push_back(leaver);
	else thenStructureNodeOrder.push_back(leaver);
}
/**
 *  @fn	void SemanticNodeBlockIf::addBlockSeize(SemanticNodeBlockSeize *seizer, bool which)
 * 
 *  @brief	Adds a block seize to 'which'. 
 * 
 *  @author	Nikola Novak
 *  @date	6/26/2009
 * 
 *  @param	seizer	If non-null, the seizer.
 *  @param	which	true to which.
 */
void SemanticNodeBlockIf::addBlockSeize(SemanticNodeBlockSeize *seizer, bool which) {
	seizers.push_back(seizer);
	if (which) elseStructureNodeOrder.push_back(seizer);
	else thenStructureNodeOrder.push_back(seizer);
}
/**
 *  @fn	void SemanticNodeBlockIf::addBlockRelease(SemanticNodeBlockRelease *releaser, bool which)
 * 
 *  @brief	Adds a block release to 'which'. 
 * 
 *  @author	Nikola Novak
 *  @date	6/26/2009
 * 
 *  @param	releaser	If non-null, the releaser.
 *  @param	which		true to which.
 */
void SemanticNodeBlockIf::addBlockRelease(SemanticNodeBlockRelease *releaser, bool which) {
	releasers.push_back(releaser);
	if (which) elseStructureNodeOrder.push_back(releaser);
	else thenStructureNodeOrder.push_back(releaser);
}
/**
 *  @fn	void SemanticNodeBlockIf::addBlockInqueue(SemanticNodeBlockInqueue *inqueuer, bool which)
 * 
 *  @brief	Adds a block inqueue to 'which'. 
 * 
 *  @author	Nikola Novak
 *  @date	6/26/2009
 * 
 *  @param	inqueuer	If non-null, the inqueuer.
 *  @param	which		true to which.
 */
void SemanticNodeBlockIf::addBlockInqueue(SemanticNodeBlockInqueue *inqueuer, bool which) {
	inqueuers.push_back(inqueuer);
	if (which) elseStructureNodeOrder.push_back(inqueuer);
	else thenStructureNodeOrder.push_back(inqueuer);
}
/**
 *  @fn	void SemanticNodeBlockIf::addBlockOutqueue(SemanticNodeBlockOutqueue *outqueuer,
 *  	bool which)
 * 
 *  @brief	Adds a block outqueue to 'which'. 
 * 
 *  @author	Nikola Novak
 *  @date	6/26/2009
 * 
 *  @param	outqueuer	If non-null, the outqueuer.
 *  @param	which		true to which.
 */
void SemanticNodeBlockIf::addBlockOutqueue(SemanticNodeBlockOutqueue *outqueuer, bool which) {
	outqueuers.push_back(outqueuer);
	if (which) elseStructureNodeOrder.push_back(outqueuer);
	else thenStructureNodeOrder.push_back(outqueuer);
}
/**
 *  @fn	void SemanticNodeBlockIf::addBlockArrive(SemanticNodeBlockArrive *arrivee, bool which)
 * 
 *  @brief	Adds a block arrive to 'which'. 
 * 
 *  @author	Nikola Novak
 *  @date	6/26/2009
 * 
 *  @param	arrivee	If non-null, the arrivee.
 *  @param	which	true to which.
 */
void SemanticNodeBlockIf::addBlockArrive(SemanticNodeBlockArrive *arrivee, bool which) {
	arrivals.push_back(arrivee);
	if (which) elseStructureNodeOrder.push_back(arrivee);
	else thenStructureNodeOrder.push_back(arrivee);
}
/**
 *  @fn	void SemanticNodeBlockIf::addBlockDepart(SemanticNodeBlockDepart *departure, bool which)
 * 
 *  @brief	Adds a block depart to 'which'. 
 * 
 *  @author	Nikola Novak
 *  @date	6/26/2009
 * 
 *  @param	departure	If non-null, the departure.
 *  @param	which		true to which.
 */
void SemanticNodeBlockIf::addBlockDepart(SemanticNodeBlockDepart *departure, bool which) {
	departures.push_back(departure);
	if (which) elseStructureNodeOrder.push_back(departure);
	else thenStructureNodeOrder.push_back(departure);
}
/**
 *  @fn	void SemanticNodeBlockIf::addBlockModelInstance(SemanticNodeBlockModelInstance *modelInstan
 *  	ce, bool which)
 * 
 *  @brief	Adds a block model instance to 'which'. 
 * 
 *  @author	Nikola Novak
 *  @date	6/26/2009
 * 
 *  @param	modelInstance	If non-null, the model instance.
 *  @param	which			true to which.
 */
void SemanticNodeBlockIf::addBlockModelInstance(SemanticNodeBlockModelInstance *modelInstance, bool which) {
	modelInstances.push_back(modelInstance);
	if (which) elseStructureNodeOrder.push_back(modelInstance);
	else thenStructureNodeOrder.push_back(modelInstance);
}
/**
 *  @fn	void SemanticNodeBlockIf::addBlockGoto(SemanticNodeBlockGoto *gotoer, bool which)
 * 
 *  @brief	Adds a block goto to 'which'. 
 * 
 *  @author	Nikola Novak
 *  @date	6/26/2009
 * 
 *  @param	gotoer	If non-null, the gotoer.
 *  @param	which	true to which.
 */
void SemanticNodeBlockIf::addBlockGoto(SemanticNodeBlockGoto *gotoer, bool which) {
	gotos.push_back(gotoer);
	if (which) elseStructureNodeOrder.push_back(gotoer);
	else thenStructureNodeOrder.push_back(gotoer);
}
/**
 *  @fn	void SemanticNodeBlockIf::addBlockIf(SemanticNodeBlockIf *ifer, bool which)
 * 
 *  @brief	Adds a block if to 'which'. 
 * 
 *  @author	Nikola Novak
 *  @date	6/26/2009
 * 
 *  @param	ifer	If non-null, the ifer.
 *  @param	which	true to which.
 */
void SemanticNodeBlockIf::addBlockIf(SemanticNodeBlockIf *ifer, bool which) {
	ifs.push_back(ifer);
	if (which) elseStructureNodeOrder.push_back(ifer);
	else thenStructureNodeOrder.push_back(ifer);
}
/**
 *  @fn	void SemanticNodeBlockIf::addBlockWait(SemanticNodeBlockWait *waiter, bool which)
 * 
 *  @brief	Adds a block wait to 'which'. 
 * 
 *  @author	Nikola Novak
 *  @date	6/26/2009
 * 
 *  @param	waiter	If non-null, the waiter.
 *  @param	which	true to which.
 */
void SemanticNodeBlockIf::addBlockWait(SemanticNodeBlockWait *waiter, bool which) {
	waiters.push_back(waiter);
	if (which) elseStructureNodeOrder.push_back((SemanticNode *)waiter);
	else thenStructureNodeOrder.push_back((SemanticNode *)waiter);
}
/**
 *  @fn	void SemanticNodeBlockIf::addBlockJoinGroup(SemanticNodeBlockJoinGroup *groupJoiner,
 *  	bool which)
 * 
 *  @brief	Adds a block join group to 'which'. 
 * 
 *  @author	Nikola Novak
 *  @date	6/26/2009
 * 
 *  @param	groupJoiner	If non-null, the group joiner.
 *  @param	which		true to which.
 */
void SemanticNodeBlockIf::addBlockJoinGroup(SemanticNodeBlockJoinGroup *groupJoiner, bool which) {
	groupJoiners.push_back(groupJoiner);
	if (which) elseStructureNodeOrder.push_back(groupJoiner);
	else thenStructureNodeOrder.push_back(groupJoiner);
}
/**
 *  @fn	void SemanticNodeBlockIf::addBlockLeaveGroup(SemanticNodeBlockLeaveGroup *groupLeaver,
 *  	bool which)
 * 
 *  @brief	Adds a block leave group to 'which'. 
 * 
 *  @author	Nikola Novak
 *  @date	6/26/2009
 * 
 *  @param	groupLeaver	If non-null, the group leaver.
 *  @param	which		true to which.
 */
void SemanticNodeBlockIf::addBlockLeaveGroup(SemanticNodeBlockLeaveGroup *groupLeaver, bool which) {
	groupLeavers.push_back(groupLeaver);
	if (which) elseStructureNodeOrder.push_back(groupLeaver);
	else thenStructureNodeOrder.push_back(groupLeaver);
}
/**
 *  @fn	void SemanticNodeBlockIf::addBlockCreate(SemanticNodeBlockCreate *creator, bool which)
 * 
 *  @brief	Adds a block create to 'which'. 
 * 
 *  @author	Nikola Novak
 *  @date	6/26/2009
 * 
 *  @param	creator	If non-null, the creator.
 *  @param	which	true to which.
 */
void SemanticNodeBlockIf::addBlockCreate(SemanticNodeBlockCreate *creator, bool which) {
	creators.push_back(creator);
	if (which) elseStructureNodeOrder.push_back(creator);
	else thenStructureNodeOrder.push_back(creator);
}
/**
 *  @fn	void SemanticNodeBlockIf::addBlockSplit(SemanticNodeBlockSplit *splitter, bool which)
 * 
 *  @brief	Adds a block split to 'which'. 
 * 
 *  @author	Nikola Novak
 *  @date	6/26/2009
 * 
 *  @param	splitter	If non-null, the splitter.
 *  @param	which		true to which.
 */
void SemanticNodeBlockIf::addBlockSplit(SemanticNodeBlockSplit *splitter, bool which) {
	splitters.push_back(splitter);
	if (which) elseStructureNodeOrder.push_back(splitter);
	else thenStructureNodeOrder.push_back(splitter);
}
/**
 *  @fn	void SemanticNodeBlockIf::addBlockGather(SemanticNodeBlockGather *gatherer, bool which)
 * 
 *  @brief	Adds a block gather to 'which'. 
 * 
 *  @author	Nikola Novak
 *  @date	6/26/2009
 * 
 *  @param	gatherer	If non-null, the gatherer.
 *  @param	which		true to which.
 */
void SemanticNodeBlockIf::addBlockGather(SemanticNodeBlockGather *gatherer, bool which) {
	gatherers.push_back(gatherer);
	if (which) elseStructureNodeOrder.push_back(gatherer);
	else thenStructureNodeOrder.push_back(gatherer);
}
/**
 *  @fn	void SemanticNodeBlockIf::addBlockExecute(SemanticNodeBlockExecute *executor, bool which)
 * 
 *  @brief	Adds a block execute to 'which'. 
 * 
 *  @author	Nikola Novak
 *  @date	6/26/2009
 * 
 *  @param	executor	If non-null, the executor.
 *  @param	which		true to which.
 */
void SemanticNodeBlockIf::addBlockExecute(SemanticNodeBlockExecute *executor, bool which) {
	executors.push_back(executor);
	if (which) elseStructureNodeOrder.push_back(executor);
	else thenStructureNodeOrder.push_back(executor);
}
/**
 *  @fn	void SemanticNodeBlockIf::setExpression(SemanticNodeExpression *expr)
 * 
 *  @brief	Sets an expression. 
 * 
 *  @author	Nikola Novak
 *  @date	6/26/2009
 * 
 *  @param	expr	If non-null, the expr.
 */
void SemanticNodeBlockIf::setExpression(SemanticNodeExpression *expr) {
	expression = expr;
}
/**
 *  @fn	std::string SemanticNodeBlockIf::toDebugString(int tab)
 * 
 *  @brief	Converts a tab to a debug string. 
 * 
 *  @author	Nikola Novak
 *  @date	6/25/2009
 * 
 *  @param	tab	The tab.
 * 
 *  @return	This object as a std::string.
 */
std::string SemanticNodeBlockIf::toDebugString(int tab) {
	std::ostringstream res;
	for (int i = 0; i < tab; i++)	res << DEBUG_STRING_RAZMAK;
	res << getLabelsDebugString() << ": if (" << std::endl << ((SemanticNode *)expression)->toDebugString(tab + 1);
	for (int i = 0; i < tab; i++)	res << DEBUG_STRING_RAZMAK;
	res << "{" << std::endl;
	for (std::vector<SemanticNode *>::iterator i = thenStructureNodeOrder.begin(); i != thenStructureNodeOrder.end(); ++i) res << (*i)->toDebugString(tab + 1);
	for (int i = 0; i < tab; i++)	res << DEBUG_STRING_RAZMAK;
	res << "} else {" << std::endl;
	for (std::vector<SemanticNode *>::iterator i = elseStructureNodeOrder.begin(); i != elseStructureNodeOrder.end(); ++i) res << (*i)->toDebugString(tab + 1);
	for (int i = 0; i < tab; i++)	res << DEBUG_STRING_RAZMAK;
	res << "}" << std::endl;
	return res.str();
}
